{% extends "base.html" %}

{% block title %}Vendors - {{ super() }}{% endblock %}

{% block content %}

<section class="content-header">
    <h1>Vendors</h1>
    <ol class="breadcrumb">
        <li><a href="{{ url_for('main.home') }}">OpenCVE</a></li>
        <li class="active">Vendors</li>
    </ol>
</section>

<section class="content">
    <div class="row">
        {% if not vendors.items %}
        <div class='col-lg-12'>
            <div class="alert alert-warning">
                No vendor found.
            </div>
        </div>
        {% else %}
        <div class='col-lg-7'>
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">Vendors ({{ vendors.total }})</h3>
                </div>
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover table-striped">
                        <tr>
                            <th>Vendor</th>
                            <th class="text-center">Products</th>
                            <th class="text-center">Actions</th>
                        </tr>
                        {% for vendor in vendors.items %}
                        <tr>
                            <td>{{ vendor.name | humanize }}</td>
                            <td class="text-center"><a href="{{ url_for('.products', vendor=vendor.name) }}">{{
                                vendor.products|length }}</a></td>
                            <td class="text-center">
                                <div class="btn-group">
                                    {% if current_user.is_authenticated %}
                                    {% if vendor in current_user.vendors %}
                                    <button class="btn btn-danger btn-xs subscribe"
                                            id="unsubscribe_vendor_{{ vendor.id }}" type="button">Unsubscribe
                                    </button>
                                    {% else %}
                                    <button class="btn btn-default btn-xs subscribe"
                                            id="subscribe_vendor_{{ vendor.id }}" type="button">Subscribe
                                    </button>
                                    {% endif %}
                                    {% else %}
                                    <a class="btn btn-default btn-xs"
                                       href="{{ url_for('user.login', next=request.url) }}" data-toggle="tooltip"
                                       data-container="body" title="You must be signed in to subscribe">Subscribe</a>
                                    {% endif %}
                                </div>
                            </td>
                        </tr>
                        {% endfor %}
                    </table>
                    <div class="center">
                        {{ pagination.links }}
                    </div>
                </div>
            </div>
        </div>

        <div class='col-lg-5'>
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">Search</h3>
                </div>
                <div class="box-body">
                    <form role="form" class="form-horizontal">
                        <div class="form-group">
                            <div class="col-md-12">
                                <div class="input-group">
                  <span class="input-group-btn">
                  <button class="btn btn-primary" type="submit"><i class="fa fa-search"></i></button>
                  </span>
                                    <form method="GET">
                                        <input type="text" placeholder="Search" class="form-control" name="search"
                                               value="{% if request.args.get('search') %}{{ request.args.get('search') }}{% endif %}">
                                    </form>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">Filter by letter</h3>
                </div>
                <div class="box-body">
                    <div class="btn-group">
                        {% for letter in letters %}
                        <a class="btn btn-very-sm {% if request.args.get('letter') != letter %}btn-default{% else %}btn-primary{% endif %}"
                           href="{{ url_for('.vendors', letter=letter) }}" type="button">{{ letter|upper }}</a>
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>

        {% endif %}
    </div>
</section>

{% endblock %}